home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / LIFE6__ / PROTO / P / PD_ABOUT.C < prev    next >
Text File  |  1991-08-16  |  9KB  |  244 lines

  1. /* PD_About_Life */
  2.  
  3. /* File name: About_Life */
  4. /* Function: Handle a modal dialog */
  5. /* History: 8/16/91 Original by Prototyper 3.0   */
  6.  
  7.  
  8. #include "PCommonLife6.h"    /* Common */
  9. #include "Common_Life6.h"    /* Common */
  10. #include "PUtils_Life6.h"    /* General Utilities */
  11. #include "Utils_Life6.h"    /* General Utilities */
  12.  
  13. #include "PD_About_Life.h"    /* This file */
  14. #include "About_Life.h"    /* The user file */
  15.  
  16.  
  17. /* ======================================================= */
  18.  
  19.  
  20. static Boolean        ExitDialog;                                             /* Flag used to exit the Dialog */
  21. static Point    MyPt;                                                         /* Current list selection point */
  22. static OSErr    MyErr;                                                      /* OS error returned */
  23. static DialogPtr    GetSelection;                                           /* Pointer to this dialog */
  24. static GrafPtr        SavedPort;                                            /* Previous grafport */
  25.  
  26. /* Prototypes */
  27. /* Filter routine for modal dialog routine */
  28. static pascal Boolean MyFilter (DialogPtr theDialog ,EventRecord *theEvent,short *itemHit);
  29.  
  30. /* This is an update routine for non-controls in the dialog */
  31. /* This is executed after the dialog is uncovered by an alert */
  32. static void Refresh_Dialog(void);                                         /* Refresh the dialogs non-controls */
  33.  
  34.  
  35.  
  36. /* ======================================================= */
  37.  
  38. /* Initialize the modal dialog, globals and call users routine */
  39.  
  40. void I_PD_About_Life()
  41. {
  42.         Rect    tempRect;                                                     /* Temporary rectangle */
  43.         short    DType;                                                         /* Type of dialog item */
  44.         short    Index;                                                         /* For looping */
  45.         Handle    DItem;                                                        /* Handle to the dialog item */
  46.         ControlHandle    CItem, CTempItem;                                /* Control handle */
  47.         Str255    sTemp;                                                     /* Get text entered, temp holding */
  48.         short    itemHit;                                                       /* Get selection */
  49.         short    temp;                                                          /* Get selection, temp holding */
  50.  
  51.  
  52.  
  53.  
  54.         D_Init_About_Life();
  55.  
  56. }                                                                                /* End of procedure */
  57.  
  58.  
  59. /* ======================================================= */
  60.  
  61. /* Filter routine for dialog events */
  62.  
  63. static pascal Boolean MyFilter (theDialog ,theEvent,itemHit)
  64. DialogPtr    theDialog;
  65. EventRecord        *theEvent;
  66. short        *itemHit;
  67. {
  68.         Point    MyPt;                                                         /* Current list selection point */
  69.         Rect    tempRect;                                                     /* Temporary rectangle */
  70.         short    DType;                                                         /* Type of dialog item */
  71.         Handle    DItem;                                                        /* Handle to the dialog item */
  72.         ControlHandle    CItem;                                               /* Control handle */
  73.         short    chCode;                                                        /* Key entered */
  74.         long    LTemp;                                                         /* Used for time delay */
  75.         char    MyCmdKey;                                                    /* The command key */
  76.         Boolean    CmdDown;                                                 /* Flag for command key used */
  77.         Boolean    valMyFilter;                                               /* Value to return */
  78.  
  79.  
  80.  
  81.         valMyFilter = D_Filter_About_Life(theDialog, theEvent, itemHit);/* Call the user routine */
  82.  
  83.         if ((theEvent->what == updateEvt)  && ((WindowPtr)theEvent->message == theDialog))/* Only do on an update */
  84.             {
  85.                 BeginUpdate(theDialog);                                        /* Start the update */
  86.                 DrawDialog(theDialog);                                         /* Draw the controls */
  87.                 valMyFilter = TRUE;                                            /* Pass out this special itemHit number */
  88.                 *itemHit = 32000;                                             /* Our special ID */
  89.             }
  90.         if (theEvent->what == mouseDown)                                /* Only do on a mouse click */
  91.             {
  92.                 MyPt = theEvent->where;                                     /* Get the point where the mouse was clicked */
  93.                 GlobalToLocal(&MyPt);                                        /* Convert global to local */
  94.  
  95.  
  96.             }
  97.         if (theEvent->what == keyDown)
  98.             {
  99.                 chCode =  theEvent->message & charCodeMask;           /* Get character */
  100.                 MyCmdKey = (char)chCode;                                    /* Change to ASCII */
  101.                 CmdDown = ((theEvent->modifiers / cmdKey) != 0);/* Get command key state */
  102.                 if (CmdDown == TRUE)                                         /* Do if command key was down */
  103.                     {
  104.                         if ((MyCmdKey == 'x') || (MyCmdKey == 'X'))
  105.                             {
  106.                                 DlgCut(theDialog);
  107.                                 valMyFilter = TRUE;
  108.                             }
  109.                         else if ((MyCmdKey =='c') || (MyCmdKey == 'C')) 
  110.                             {
  111.                                 DlgCopy(theDialog);
  112.                                 valMyFilter = TRUE;
  113.                             }
  114.                         else if ((MyCmdKey =='v') || (MyCmdKey == 'V'))
  115.                             {
  116.                                 DlgPaste(theDialog);
  117.                                 valMyFilter = TRUE;
  118.                             }
  119.                     }
  120.                 else if ((chCode == 13) || (chCode == 3))                    /* CR or Enter */
  121.                     {
  122.                         valMyFilter = TRUE;                                     /* Flag we got a hit */
  123.                         *itemHit = 1;                                             /* Default for CR */
  124.                         GetDItem (theDialog ,*itemHit, &DType, &DItem, &tempRect);/* Get the item */
  125.                         if (DType == (ctrlItem + btnCtrl))                     /* If a button then ... */
  126.                             {
  127.                                 CItem = (ControlHandle)DItem;                  /* Make it a controlhandle */
  128.                                 HiliteControl(CItem, 10);                         /* Hilite it */
  129.                                 LTemp = TickCount() + 15;                       /* Flash the button for 1/4 second */
  130.                                 do
  131.                                 {}
  132.                                 while (LTemp > TickCount());
  133.                                 HiliteControl(CItem, 0);                          /* UnHilite it */
  134.                             }
  135.                     }
  136.             }
  137.  
  138.         return(valMyFilter);
  139. }
  140.  
  141. /* ======================================================= */
  142.  
  143.  
  144.  
  145. /* ======================================================= */
  146.  
  147. /* This is an update routine for non-controls in the dialog */
  148. /* This is executed after the dialog is uncovered by an alert */
  149. static void Refresh_Dialog()                                               /* Refresh the dialogs non-controls */
  150.         Rect    rTempRect;                                                    /* Temp rectangle used for drawing */
  151.         short    DType;                                                         /* Type of dialog item */
  152.         Handle    DItem;                                                        /* Handle to the dialog item */
  153.         ControlHandle    CItem;                                               /* Control handle */
  154.  
  155.  
  156.  
  157.         SetPort(GetSelection);                                               /* Point to our dialog window */
  158.         GetDItem(GetSelection,Res_Dlg_Big_Deal,&DType,&DItem,&tempRect);/* Get the item handle */
  159.         PenSize(3, 3);                                                         /* Change pen to draw thick default outline */
  160.         InsetRect(&tempRect, -4, -4);                                     /* Draw outside the button by 1 pixel */
  161.         FrameRoundRect(&tempRect, 16, 16);                            /* Draw the outline */
  162.         PenSize(1, 1);                                                         /* Restore the pen size to the default value */
  163.  
  164.  
  165.         D_Refresh_About_Life(GetSelection);                             /* Call user refresh routine */
  166.  
  167. }
  168.  
  169. /* ======================================================= */
  170.  
  171.  
  172. void PD_About_Life()
  173. {
  174.         Rect    tempRect;                                                     /* Temporary rectangle */
  175.         short    DType;                                                         /* Type of dialog item */
  176.         short    Index;                                                         /* For looping */
  177.         Handle    DItem;                                                        /* Handle to the dialog item */
  178.         ControlHandle    CItem;                                               /* Control handle */
  179.         ControlHandle    CTempItem;                                         /* temp Control handle */
  180.         Str255    sTemp;                                                     /* Get text entered, temp holding */
  181.         short    itemHit;                                                       /* Get selection */
  182.         short    temp;                                                          /* Get selection, temp holding */
  183.  
  184.  
  185.  
  186.         GetPort(&SavedPort);                                               /* Get the previous grafport */
  187.  
  188.  
  189.         GetSelection = GetNewDialog(Res_D_About_Life, NIL,  (Ptr)-1);/* Bring in the dialog resource */
  190.         tempRect = GetSelection->portRect;                               /* Get window size, we will now center it */
  191.         tempRect.top = ((screenBits.bounds.bottom - screenBits.bounds.top) - (tempRect.bottom - tempRect.top)) / 2;/* Center vert */
  192.         tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left) - (tempRect.right - tempRect.left)) / 2;/* Center Horz */
  193.         MoveWindow(GetSelection, tempRect.left, tempRect.top, TRUE);/* Now move the window to the proper position */
  194.         ShowWindow(GetSelection);                                         /* Open a dialog box */
  195.         SelectWindow(GetSelection);                                        /* Lets see it */
  196.         SetPort(GetSelection);                                               /* Prepare to add conditional text */
  197.  
  198.  
  199.         /* Setup initial conditions */
  200.         Refresh_Dialog();                                                      /* Draw any Lists, lines, or rectangles */
  201.  
  202.         ExitDialog = FALSE;                                                   /* Do not exit dialog handle loop yet */
  203.  
  204.         D_Setup_About_Life(GetSelection);                                /* Call user Dialog setup routine */
  205.  
  206.         do                                                                        /* Start of dialog handle loop */
  207.         {
  208.                 ModalDialog(&MyFilter, &itemHit);                         /* Wait until an item is hit */
  209.  
  210.                 if (itemHit == 32000)                                          /* Check for update */
  211.                     {
  212.                         Refresh_Dialog();                                         /* Draw any Lists, lines, or rectangles*/
  213.                         EndUpdate(GetSelection);                                /* End of the update*/
  214.                     }
  215.                 else
  216.                     {
  217.                         GetDItem(GetSelection, itemHit, &DType, &DItem, &tempRect);/* Get item information */
  218.                         CItem = (ControlHandle)DItem;                         /* Get the control handle */
  219.                     }
  220.  
  221.                 D_Hit_About_Life(GetSelection,itemHit,&ExitDialog);/* Let user handle the item hit */
  222.  
  223.                 /* Handle it real time */
  224.                 if (itemHit ==Res_Dlg_Big_Deal)                             /* Handle the Button being pressed */
  225.                     {
  226.                         ExitDialog = TRUE;                                       /* Close this dialog, exit */
  227.                     }
  228.  
  229.  
  230.         }
  231.         while (ExitDialog == FALSE);                                        /* Handle dialog items until exit selected */
  232.  
  233.  
  234.         D_Exit_About_Life(GetSelection);                                 /* Exiting the modal dialog */
  235.  
  236.         SetPort(SavedPort);                                                 /* Restore the previous grafport */
  237.  
  238.         DisposDialog(GetSelection);                                         /* Flush the dialog out of memory */
  239.  
  240.  
  241. }                                                                                /* End of procedure */
  242.  
  243.